
import { BaseComp } from '../../../common/component/comp';
import { BanPick } from '../../compute/banPick';
import { Panel } from './panel';
import { BanBar } from './banSeat';

class Painter extends BaseComp {
	/** @type {BanPick} */
	banPick = null;
	lastHandler = 0;
	constructor(args) {
		super(null);
		const zrender = this.zrender = args.zrender;
		const zr = this.zr = args.zr;
		this.context = args.context;
		this.banPick = args.banPick;

		this.panel = new Panel({
			zrender, zr, parent: this
		});
		this.leftBan = new BanBar({
			zrender, zr, parent: this, left: true
		});
		this.rightBan = new BanBar({
			zrender, zr, parent: this, left: false
		});

		this.startTick = this.startTick.bind(this);
	}

	init() {
		this.lastHandler = requestAnimationFrame(this.startTick);
	}

	startTick() {
		this._tick();
	}

	destroy() {
		super.destroy();
		cancelAnimationFrame(this.lastHandler);
	}

	tick() {
		this.lastHandler = requestAnimationFrame(this.startTick);
	}
}

export { Painter };
